package database;

import logic.baselogic.Person;

/**
 * Created by IntelliJ IDEA.
 * User: grigory.rozhkov
 * Date: 12.09.12
 * Time: 0:47
 * To change this template use File | Settings | File Templates.
 */
public class DBPerson extends AbstractDBObject {

    private Person person;
    private String id;
    private boolean deleted;

    public DBPerson() {

    }

    public DBPerson(String id, Person person) {
        this.id = id;
        this.person = person;
        deleted = false;
    }

    public boolean create(String id, String... fields) {
        if (fields.length > Person.NUMBER_OF_FEATURES) {
            return false;
        }
        this.person = new Person(fields);
        this.id = id;
        this.deleted = false;
        return true;
    }

    public boolean update(String... fields) {
        if (fields.length > Person.NUMBER_OF_FEATURES) {
            return false;
        }
        person.updateFields(fields);
        return true;
    }

    public Object getValue() {
        return person;
    }

    public String getId() {
        return id;
    }

    public String convertToString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("ID: ");
        stringBuilder.append(id);
        stringBuilder.append(" INFO: ");
        stringBuilder.append(person.toString());
        return stringBuilder.toString();
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void delete() {
        deleted = true;
    }
}
